package com.xiyuan.almighty.service;

import org.apache.commons.lang3.ObjectUtils;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @创建人 袁继鑫
 * @创建时间 2021-03-25 16:23
 * @版本 1.0
 * @描述
 */
public class DateTest {
    public static void main(String[] args) {

        List list = new ArrayList();
        ObjectUtils.isNotEmpty(list);
        list.isEmpty();


        LocalDateTime dt = LocalDateTime.now(); // 当前日期和时间
        LocalDate d = dt.toLocalDate(); // 转换到当前日期
        LocalTime t = dt.toLocalTime(); // 转换到当前时间
        System.out.println(dt);
        System.out.println(d);
        System.out.println(t);


        // 自定义格式化:
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        System.out.println(dtf.format(LocalDateTime.now()));

        // 用自定义格式解析:
        LocalDateTime dt2 = LocalDateTime.parse("2019/11/30 15:16:17", dtf);
        System.out.println(dt2);


        LocalDateTime dt1 = LocalDateTime.of(2019, 10, 26, 20, 30, 59);
        System.out.println(dt1);
        // 加5天减3小时:
        LocalDateTime dt3 = dt1.plusDays(5).minusHours(3);
        System.out.println(dt3); // 2019-10-31T17:30:59
        // 减1月:
        LocalDateTime dt4 = dt1.minusMonths(1);
        System.out.println(dt4); // 2019-09-30T17:30:59
        ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
        int i = threadLocalRandom.nextInt(100);
        System.out.println("i = " + i);
        double random = Math.random();
        System.out.println("random = " + random);
    }
}
